package com.example.http;

import com.google.gson.Gson;

import java.io.IOException;
import java.lang.reflect.Field;
import java.util.concurrent.TimeUnit;

import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class HttpClient {
    public final static String BASE_URL = "http:/106.15.46.6:8085/";
    public final static String BAIDU_OAUTH_URL = "https://aip.baidubce.com/oauth/2.0/";
    public final static String BAIDU_FACE_URL = "https://aip.baidubce.com/rest/2.0/face/v3/";


    private static HttpClient instance;
    public static HttpClient getInstance() {
        if (instance == null) {
            synchronized (HttpClient.class) {
                if (instance == null) {
                    instance = new HttpClient();
                }
            }
        }
        return instance;
    }
    public Retrofit.Builder getBuilder(String apiUrl) {
        Retrofit.Builder builder = new Retrofit.Builder();
        builder.client(getClient());
        builder.baseUrl(apiUrl);//设置远程地址
        builder.addConverterFactory(GsonConverterFactory.create());

        builder.addCallAdapterFactory(RxJava2CallAdapterFactory.create());

        return builder;
    }
    public OkHttpClient getClient(){

        OkHttpClient  okHttpClient = new OkHttpClient.Builder()



//                .connectTimeout(5*1000, TimeUnit.MILLISECONDS) //链接超时
//                .readTimeout(10*1000,TimeUnit.MILLISECONDS) //读取超时
//                .writeTimeout(10*1000,TimeUnit.MILLISECONDS) //写入超时

                .build();



        return  okHttpClient;
    }
}
